<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>注册</title>
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta2/css/all.min.css">
    <link rel="stylesheet" href="zhuce.css">
    <script>
        function nameCheck(){
            //三到四位文字
            let reg = /^[\u4e00-\u9fa5]{3,4}$/;
            let name =document.getElementById("text").value;
            if (!reg.test(name) || name=='') {
            return false;
            }else{
            return true;
            }

        }
        
        function pwdCheck() {
            //六到十二位任意字符
            let reg = /^[\s\S]{6,12}/;
        let pwd = document.getElementById("password").value;
        if(!reg.test(pwd) || pwd==''){
            return false;
        }else{
            return true;
        }
    }
        function pwdCheck2(){
            let pwd = document.getElementById("password").value;
            let pwd2 = document.getElementById("password2").value;
            if(pwd != pwd2){
                alert("两次密码输入的不正确！");
                return false;
            }else{
                return true;
            }
            
    }
    var storage=window.localStorage;

    function yonghu(id,password){
        this.id=id;
        this.password=password;
    };
    
    
function test(){
    if(nameCheck() && pwdCheck() && pwdCheck2()){
        let name =document.getElementById("text").value;
    let pwd = document.getElementById("password").value;
    const arr7=[{
     id:document.getElementById("text").value,
    password:document.getElementById("password").value,
    }
]
        localStorage.setItem("arr7",JSON.stringify(arr7));
        alert('注册成功，请前往登陆界面！');
        window.location.href="denglu_wz.html"

    }
    else{
        alert('你输入的有误，请按要求提交！');
    }
}
 
    </script>
</head>
<body> 
    <div class="enroll">
        <h2>王者注册</h2>
        <div class="enroll-box">
            <input type="text" placeholder="账号" id="text">
        </div>
        <div class="enroll-box">
            <!-- <i class="fas fa-eye-slash show_hide"></i> -->
            <input type="password" placeholder="密码" id="password">
        </div>
        <div class="indicator">
            <div class="icon-text">
                <i class="fas fa-exclamation-circle error_icon"></i>
                <h6 class="text">只能输入数字，字母，下划线</h6>
            </div>
        </div>
        <div class="enroll-box">
            <input type="password" placeholder="确认密码" id="password2">
        </div>
        <div class="enroll-box">
            <button class="ch-bpx" onclick="test()">注册</button>
        </div>
        <div class="verify">
            <input type="checkbox"><p>我已同意用户协议</p>
        </div>

        <div class="help">
            <div class="hp"><a href="denglu_wz.html"><p>登录</p></a></div>
            <div class="hp2"><a href="#"><p>帮助</p></a></div>
        </div>
    </div>

    <script>
        nameCheck();
        pwdCheck();
        pwdCheck2();
    </script>
</body>
</html>